package com.bw.play.view

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.base.app.RoutePath
import com.bw.common.mvi.BaseMviFragment
import com.bw.play.R
import com.bw.play.databinding.FragmentIntroduceBinding
import com.bw.play.intent.PlayViewIntent
import com.bw.play.vm.PlayViewModel


@Route(path = RoutePath.PATH_FRAGMENT_DETAIL_INTRODUCE)
class IntroduceFragment : BaseMviFragment<FragmentIntroduceBinding>() {

    private val mViewModel: PlayViewModel by activityViewModels()

    @Autowired
    @JvmField
    var userId: String = ""

    @Autowired
    @JvmField
    var moduleType: Int = 0

    @Autowired
    @JvmField
    var videoTypeId: Int = -1 //推荐

    @Autowired
    @JvmField
    var channelId: String = ""


    private var pageIndex = 1
    private var pageSize = 10


    override fun getLayoutId(): Int = R.layout.fragment_introduce

    override fun initViews() {
        ARouter.getInstance().inject(this)

    }

    override suspend fun sendViewIntent() {
        //获取作者信息
        mViewModel.channel.send(PlayViewIntent.LoadAuthorInfo(userId))
        //加载视频列表
        when (moduleType) {
            //从首页模块进入
            0 -> {
                if (videoTypeId == -1) {
                    mViewModel.channel.send(
                        PlayViewIntent.LoadRecommendSimpleVideo(
                            pageIndex,
                            pageSize
                        )
                    )
                } else {
                    mViewModel.channel.send(
                        PlayViewIntent.LoadSimpleVideoByChannelId(
                            channelId,
                            pageIndex,
                            pageSize
                        )
                    )
                }
            }
            //从放映厅模块进入
            1 -> {
                if (videoTypeId == -1) {
                    mViewModel.channel.send(
                        PlayViewIntent.LoadRecommendMultiVideo(
                            pageIndex,
                            pageSize
                        )
                    )
                } else {
                    mViewModel.channel.send(
                        PlayViewIntent.LoadMultiVideoByTypeId(
                            videoTypeId,
                            pageIndex,
                            pageSize
                        )
                    )
                }
            }
        }

    }

    override suspend fun collectUIState() {

    }


}